import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      redirect:{name:"ShouYe"},
      children:[
        {
          path:"/home/company",
          name:"company",
          component: () => import('../page/home/company.vue'), 
        },
        {
          path:"/home/ShouYe",
          name:"ShouYe",
          component: () => import('../page/home/ShouYe.vue'),
        },
        {
          path:"/UesrSystem",
          name:"User",
          component: () => import('../views/system/UesrSystem.vue'),
        },
        {
          path:"/QuestionView",
          name:"Question",
          component: () => import('../views/system/QuestionView.vue'),
        },
        {
          path:"/ReplyView",
          name:"ReplyView",
          component: () => import('../views/system/ReplyView.vue'),
        },
        {
          path:"/SecretView",
          name:"SecretView",
          component: () => import('../views/system/SecretView.vue'),
        },
        {
          path:"/ProfileView",
          name:"个人中心",
          component: () => import('../views/system/ProfileView.vue'),
          redirect:{name:"基本资料"},
          children:[
            {
              path:"/Bisic",
              name:"基本资料",
              component: () => import('../components/Bisic.vue'),
            },
             {
              path:"/Pass",
              name:"修改密码",
              component: () => import('../components/Pass.vue'),
            },
          ]
        },
        
        {
          path:"/home/Free",
          name:"Free",
          component: () => import('../page/home/Free.vue'),
        },
        {
          path:"/home/Consultants",
          name:"Consultants",
          component: () => import('../page/home/consultants/Consultants.vue'),
        },
        {
          path:"/home/ConsultantLevels",
          name:"ConsultantLevels",
          component: () => import('../page/home/consultants/ConsultantLevels.vue'),
        },
        {
          path:"/home/ConsultantsField",
          name:"ConsultantsField",
          component: () => import('../page/home/consultants/ConsultantsField.vue'),
        },
        {
          path:"/home/ConsultantCertificate",
          name:"ConsultantCertificate",
          component: () => import('../page/home/consultants/ConsultantCertificate.vue'),
        },
        {
          path:"/home/Charge",
          name:"Charge",
          component: () => import('../page/home/consultants/Charge.vue'),
        },
        {
          path:"/views/system/HeartkView",
          name:"Heartk",
          component: () => import('../views/system/HeartkView.vue'),
        },
        {
          path:"/views/system/HeartMarkView",
          name:"HeartMark",
          component: () => import('../views/system/HeartMarkView.vue'), 
        },
        {
          path:"/views/system/MyTestView",
          name:"MyTest",
          component: () => import('../views/system/MyTestView.vue'),
        },
        {
          path:"/views/system/CourseTypeView",
          name:"CourseType",
          component: () => import('../views/system/CourseTypeView.vue'),
        },
        {
          path:"/views/system/CourseView",
          name:"Course",
          component: () => import('../views/system/CourseView.vue'),
        },
        {
          path:"/views/system/FmView",
          name:"Fm",
          component: () => import('../views/system/FmView.vue'),
        },
        {
          path:"/home/Appointment",
          name:"Appointment",
          component: () => import('../page/home/cousoult/Appointment.vue'), 
        },
        {
          path:"/home/UserMark",
          name:"UserMark",
          component: () => import('../page/home/cousoult/UserMark.vue'),

        },
        {
          path:"/views/system/CourseTalkView",
          name:"CourseTalk",
          component: () => import('../views/system/CourseTalkView.vue'),
        },
        {
          path:"/views/system/CourseReplyView",
          name:"CourseReply",
          component: () => import('../views/system/CourseReplyView.vue'),

        },
        {
          path:"/views/system/CourseBuyView",
          name:"CourseBuy",
          component: () => import('../views/system/CourseBuyView.vue'),
        },
        {
          path:"/home/cousoult",
          name:"cousoult",
          redirect:{name:"publicity"},
          children:[
            {
              path:"/home/cousoult/publicity",
              name:"publicity",
              component: () => import('../page/home/cousoult/Publicity.vue'),
            }, 
          ]
        },
        {
          path:"/home/article",
          name:"My",
          children:[
            {
              path:"/home/article/articleType",
              name:"articleType",
              component: () => import('../page/home/article/ArticleType.vue'),
            },
            {
              path:"/home/article/articleList",
              name:"articleList",
              component: () => import('../page/home/article/ArticleList.vue'),
            }
          ]
        },
        {
          path:"/home/courseMark",
          name:"courseMark",
          component: () => import('../page/home/CourseMark.vue'),
        }
      ]
    },
    {
      path: '/',
      name: 'logIn',
      component: () => import('../views/longInView.vue'),
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
    },
  ],
})

//路由守卫
router.beforeEach((to, from, next) => {
  if(to.path == '/'){
    next() 
  }else{
   const token = localStorage.getItem('token')
   if(token){
    next() 
   } else{
    next('/') 
   }
  }
})

export default router
